<?php

namespace app\admin\model;

use app\common\model\TimeModel;
use think\facade\Log;
use think\model\concern\SoftDelete;

class DataStoreBalanceLog extends TimeModel
{
    use SoftDelete;

    protected $name = "data_store_balance_log";

    protected $table = "";

    protected $deleteTime = "delete_time";


    public static function onAfterWrite($model){
        $store =  new DataStoreUser();
        $store = $store->find(['id'=>$model->store_id]);
        if($store->status == 1){
            $save = [
                'store_id'=>$store->id,
                'code' => "Y".time()
            ];
            DataUserLotteryNum::create($save);
        }
    }
    public static function onAfterInsert($model){
       $store =  new DataStoreUser();
       $store = $store->find(['id'=>$model->store_id]);
       if($model->type==0){
           $store->balance = $store->balance+ $model->real_price;
           $store->save();
       }else{
           if($model->pay_type==1){
               $store->balance = $store->balance - $model->real_price;
               $store->save();
           }
           $save = [
               'store_id'=>$store->id,
               'code' => "Y".time()
           ];
           DataUserLotteryNum::create($save);

       }
    }
    

}